// pages/person/track.js
const app = getApp()
const wh = require("../../utils/wh.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shop: [],
    page: 1,
    page_size: 5,
    no_data: 0,
    onearth: false, // 是否已经到达底部
    have: true,
  },
  // 获取用户足迹展示列表
  getFootList(){
    let that = this;
    let page_size = this.data.page_size,
      no_data = this.data.no_data,
      page = this.data.page;
    if (no_data == 0) {
      wh.Post('/api/mall.footmark/mylist', {
        page: page,
        page_num: page_size,
      }, function (res) {
        console.log(res)
        let shop = that.data.shop.concat(res),
          count = res.length;
        console.log(res)
        if (page_size > count) {
          that.data.no_data = 1;
          if (shop.length > 3) {
            that.setData({
              onearth: true
            })
          }
        }
        that.setData({
          shop: shop
        })
        if (that.data.shop.length == 0) {
          that.setData({
            have: false,
          });
        } else {
          that.setData({
            have: true,
          });
        }
      })
    }
  },
  // 跳转
  trackTo(e){
    console.log(e)
    let that=this,
    shop=this.data.shop,
    types = e.currentTarget.dataset.type,
    target_id = e.currentTarget.dataset.target_id;
    if (types == 1) {
      wx.navigateTo({
        url: '../hotel/hotel?shop_id=' + target_id,
      })
    } else if (types==2){
      wx.navigateTo({
        url: '../events/events?activityId=' + target_id,
      })
    } else if (types == 3){
      wx.navigateTo({
        url: '../details/details?goods_id=' + target_id,
      })
    } else if (types == 4) {
      wx.navigateTo({
        url: '../cutDetails/cutDetails?bargainId=' + target_id,
      })
    } else if (types == 5) {
      wx.navigateTo({
        url: '../killDetails/killDetails?seckill_id=' + target_id,
      })
    } else if (types == 6) {
      wx.navigateTo({
        url: '../groupDetails/groupDetails?group_id=' + target_id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getFootList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      no_data: 0,
      page: 1,
      page_size: 5,
      onearth: false,
      shop: [],
    });
    this.getFootList()
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let no_data = this.data.no_data,
      page = this.data.page,
      page_size = this.data.page_size;
    if (no_data == 0) {
      this.data.page = page + 1;
      this.getFootList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})